package com.lujianfei.httprequest

import com.google.gson.GsonBuilder
import com.lujianfei.httprequest.intercepter.HeadInterceptor
import okhttp3.ConnectionPool
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

object RetrofitManager {

    private var client = OkHttpClient.Builder()
            .addInterceptor(HeadInterceptor())
            .addInterceptor(HttpLoggingInterceptor()
            .setLevel(HttpLoggingInterceptor.Level.BODY))
            .connectTimeout(8, TimeUnit.SECONDS)
            .readTimeout(15, TimeUnit.SECONDS)
            .writeTimeout(15, TimeUnit.SECONDS)
            .connectionPool(ConnectionPool(32,5,TimeUnit.MINUTES))
            .build()

    var retrofit: Retrofit = Retrofit.Builder()
            .client(client)
            .baseUrl(Constant.Http.baseUrl)
            .addConverterFactory(GsonConverterFactory
                    .create(GsonBuilder().serializeNulls().setLenient().create())
            )
            .build()
}